﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MatrixConverter
{
    internal class Program
    {
        static void Main()
        {
            double[,] matrix = {
            { 0, 2, 0 },
            { 0, 3, 0 },
            { 0, 4, 0 }
        };

            double[,] resultMatrix = RemoveEmptyColumns(matrix);

            PrintMatrix(resultMatrix);

            Console.ReadLine();
        }

        static double[,] RemoveEmptyColumns(double[,] matrix)
        {
            int rows = matrix.GetLength(0);
            int cols = matrix.GetLength(1);

            List<int> notEmpColumnIndexs = new List<int>();
            for (int col = 0; col < cols; col++)
            {
                bool isEmptyColumn = true;
                for (int row = 0; row < rows; row++)
                {
                    if (matrix[row, col] != 0)
                    {
                        isEmptyColumn = false;
                        break;
                    }
                }

                if (!isEmptyColumn)
                {
                    notEmpColumnIndexs.Add(col);
                }
            }

            double[,] result = new double[rows, notEmpColumnIndexs.Count];
            for (int newCol = 0; newCol < notEmpColumnIndexs.Count; newCol++)
            {
                int originalCol = notEmpColumnIndexs[newCol];
                for (int row = 0; row < rows; row++)
                {
                    result[row, newCol] = matrix[row, originalCol];
                }
            }
            return result;
        }

        static void PrintMatrix(double[,] matrix)
        {
            int rows = matrix.GetLength(0);
            int cols = matrix.GetLength(1);

            for (int row = 0; row < rows; row++)
            {
                for (int col = 0; col < cols; col++)
                {
                    Console.Write(matrix[row, col] + " ");
                }
                Console.WriteLine();
            }
        }
    }
}
